package info.hexin.aop3;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;

public class ClassAdapter extends ClassVisitor {

    public ClassAdapter(int api, ClassVisitor cv) {
        super(api, cv);
    }

    /**
     * 类描述
     */
    @Override
    public void visit(final int version, final int access, final String name, final String signature,
            final String superName, final String[] interfaces) {
        cv.visit(version, access, name + "$1", signature, superName, interfaces);
    }

    @Override
    public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
            final String[] exceptions) {
        System.out.println("============  "+name+"   =============");
        System.out.println(access);
        System.out.println(name);
        System.out.println(desc);
        System.out.println(signature);
        System.out.println(exceptions);
//        if ("execute".equals(name)) {
//            // 这里只是简单的比较了方法名字，其实还需要比较方法参数，参数信息在desc中
//            return cv.visitMethod(access, name + "$1", desc, signature, exceptions);
//        }
        if("<init>".equals(name)){
            return cv.visitMethod(access, name, desc, signature, exceptions);
        }
        return cv.visitMethod(access, name+"$1", desc, signature, exceptions);
    }

}
